from models import Model
from sklearn.metrics import f1_score, precision_score, recall_score, make_scorer
from sklearn.svm import SVC
from sklearn.linear_model import LogisticRegressionCV

from finetune import FineTune
import pandas as pd
import numpy as np


def get_x_y(filename):
    data = pd.read_csv(filename)
    x = data.iloc[:, :-1].to_numpy()
    y = data.iloc[:, -1].to_numpy(dtype=np.int64)
    feature_names = list(data.columns)[:-1]

    return x, y, feature_names


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    x, y, features = get_x_y("./data/diabetes.csv")
    evals = {"svm": SVC(probability=True), "logit": LogisticRegressionCV(cv=5, max_iter=1000)}
    score_fun = {"f1_score": f1_score, "recall": recall_score, "precision": precision_score, "roc": None}

    params = {"C": 0.1, "kernel": 'rbf', 'probability': True}

    f1 = make_scorer(f1_score)
    fine = FineTune(SVC, params, f1)
    clf = fine.tune((x, y))
    model = Model(clf, score_fun, evals, test_size=0.2)
    model.fit(x, y, features)


